
export function query(str,el=document){
    return el.querySelector(str)
}
export function queryAll(str,el=document){
    return el.querySelectorAll(str)
}


export function getBoundingClientRect(el){
    return el.getBoundingClientRect()
}

/**
 * 
 * t: current time（当前时间）
 * b: beginning value（初始值）
 * c: change in value（变化量）
 * d: duration（持续时间）
 */
 export function Linear(t, b, c, d) {
    return (c - b) * t / d + b;
    // return c * t / d + b;
}

//添加事件
export function onFn(element, event, handler) {
    if (document.addEventListener) {
        if (element && event && handler) {
            element.addEventListener(event, handler, false);
        }
    } else {
        if (element && event && handler) {
            element.attachEvent('on' + event, handler);
        }
    }
}
//删除事件
export function offFn(element, event, handler) {
    if (document.addEventListener) {
        if (element && event && handler) {
            element.removeEventListener(event, handler, false);
        }
    } else {
        if (element && event && handler) {
            element.detachEvent('on' + event, handler);
        }
    }
}
//只绑定一次
export function onceFn(el, event, fn) {
    var listener = function () {
        if (fn) {
            fn.apply(this, arguments);
        }
        offFn(el, event, listener);
    };
    onFn(el, event, listener);
}
//判断元素上有没有这个 class
export function hasClass(el, cls) {
    if (!el || !cls) return false;
    if (trim(cls).indexOf(' ') !== -1) throw new Error('className should not contain space.');
    if (el.classList) {
        return el.classList.contains(cls);
    } else {
        return (' ' + el.className + ' ').indexOf(' ' + cls + ' ') > -1;
    }
}
//添加class
export function addClass(el, cls) {
    if (!el) return;
    var curClass = el.className;
    var classes = trim(cls || '').split(' ');
    for (var i = 0, j = classes.length; i < j; i++) {
        var clsName = classes[i];
        if (!clsName) continue;
        if (el.classList) {
            el.classList.add(clsName);
        } else {
            if (!hasClass(el, clsName)) {
                curClass += ' ' + clsName;
            }
        }
    }
    if (!el.classList) {
        el.className = trim(curClass);
    }

}
//移除对象上的class
export function removeClass(el, cls) {
    if (!el) return;
    var curClass = el.className,
        classes = trim(cls || '').split(' ');
    for (var i = 0, j = classes.length; i < j; i++) {
        var clsName = classes[i];
        if (!clsName) continue;
        if (el.classList) {
            el.classList.remove(clsName);
        } else {
            curClass = curClass.replace(' ' + clsName + ' ', ' ');
        }
    }
    if (!el.classList) el.className = trim(curClass);
}
//去掉前后的空格
export function trim(string) {
    return (string || '').replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, '');
}
export function trimr(string) {
    return (string || '').replace(/[\s\uFEFF]+$/g, '');
}
export function triml(string) {
    return (string || '').replace(/^[\s\uFEFF]+/g, '');
}